package com.choosefine.paycenter.webgateway.pay.web.controller;

import com.choosefine.paycenter.account.enums.RoleType;
import com.choosefine.paycenter.common.dto.JSONResult;
import com.choosefine.paycenter.common.utils.JSONResultGenerator;
import com.choosefine.paycenter.pay.model.Channel;
import com.choosefine.paycenter.pay.service.ChannelService;
import com.google.common.collect.Lists;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.management.relation.Role;
import java.util.List;

/**
 * Created by Administrator on 2017/4/18.
 */
@Api(value = "支付渠道",description = "邓友谊")
@RestController
@RequestMapping("channel")
public class ChannelController {

    @Autowired
    private ChannelService channelService;

    /**
     * 查询支付渠道列表
     * @return
     */
    @ApiOperation("查询支付渠道列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "device", dataType = "String", allowableValues = "PC,APP",paramType = "path", required = true, value = "PC,或APP"),
    })
    @GetMapping("{device}")
    public JSONResult selectChannelList(@PathVariable("device") String device, @Param("roleId") Long roleId){
        Boolean isPublic = null;Boolean isPrivate = null;
        //个人
        if(null != roleId && roleId.longValue() >= RoleType.WK.getValue().longValue() && roleId.longValue() <= RoleType.MG.getValue().longValue()){
            isPrivate = true;
        }
        //其他情况为企业
        if(null != roleId && roleId.longValue() >= RoleType.CC.getValue().longValue() && roleId.longValue() <= RoleType.FS.getValue().longValue()){
            isPublic = true;
        }
        List<Channel> channellist = Lists.newArrayList();
        if(null == isPrivate && null != isPublic && isPublic){
            channellist = channelService.findChannelList("B2B");
        }else if(null == isPrivate && null == isPublic) {
            channellist = channelService.findAllChannelList();
        }else if(null != isPrivate && isPrivate && null == isPublic){
            channellist = channelService.findChannelList("B2C");
        }
        if(device.equalsIgnoreCase("PC")){
            for (Channel channel : channellist) {
                channel.setPayType(channel.getPayType() + "_NB");
            }
        }
        if(device.equalsIgnoreCase("APP")){
            for(Channel channel : channellist){
                channel.setPayType(channel.getPayType()+"_APP");
            }
        }
        return JSONResultGenerator.buildQuerySuccessResult(channellist);
    }

}
